<script>
import config from './config.js'

// 添加请求拦截器
const httpInterceptor = {
  invoke(options) {
    // 拼接基础路径
    options.url = config.baseURL + options.url
    
    // 判断是否是公开API
    const isPublicAPI = [
      '/api/carousel/list',
      '/api/scenic/list',
      '/api/scenic/info',
      '/api/guide/list',
      '/api/food/list',
      '/api/specialty/list'
    ].some(path => options.url.includes(path))
    
    // 只有非公开API才需要token
    if (!isPublicAPI) {
      const token = uni.getStorageSync('token')
      if (token) {
        options.header = {
          ...options.header,
          'Authorization': token
        }
      }
    }
  }
}

export default {
  onLaunch: function() {
    // 注册请求拦截器
    uni.addInterceptor('request', httpInterceptor)
  },
  onShow: function() {
    console.log('App Show')
  },
  onHide: function() {
    console.log('App Hide')
  }
}
</script>

<style lang="scss">
	// @import "uview-ui/index.scss";
@import '@/uni_modules/uni-icons/components/uni-icons/uniicons.css';
</style>
